//轮播图
let select = document.querySelectorAll(".slideshow p a");
let show = document.querySelectorAll(".slideshow .imgs img");
let slideshow = document.querySelector(".slideshow");
let sl = document.querySelector(".slideshow .sl");
let sr = document.querySelector(".slideshow .sr");
let times;

for (let i = 0; i < select.length; i++) {
    select[i].addEventListener("mouseenter", function () {
        index = i;
        play(index);
    })
}

let index = 0;

function playtimes() {
    times = setInterval(function () {
        index++;
        if (index == show.length) {
            index = 0;
        }
        play(index);
    }, 2000)
}

playtimes();

//移入到大盒子就停止
slideshow.addEventListener("mouseenter", function () {
    clearInterval(times);
})
slideshow.addEventListener("mouseleave", function () {
    playtimes();
})


sl.addEventListener("click", function () {
    index--;
    if (index < 0) {
        index = show.length - 1;
    }
    play(index);
})
sr.addEventListener("click", function () {
    index++;
    if (index > 3) {
        index = 0;
    }
    play(index);
})

function play(index) {
    for (let j = 0; j < select.length; j++) {
        select[j].classList.remove("select");
        show[j].classList.remove("show");
    }
    select[index].classList.add("select");
    show[index].classList.add("show");
}